Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.579 lượt xem;
- ClickAndDrag.cs
- DemoChangeOwner /
- Demos /
- Photon Unity Networking /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 public class ClickAndDrag : Photon.MonoBehaviour
5 {
6 private Vector3 camOnPress;
7 private bool following;
8 private float factor = -0.1f;
9
10 // Update is called once per frame
11 void Update ()
12 {
13 if (!photonView.isMine)
14 {
15 return;
16 }
17
18 InputToEvent input = Camera.main.GetComponent<InputToEvent>();
19 if (input == null) return;
20 if (!following)
21 {
22 if (input.Dragging)
23 {
24 camOnPress = this.transform.position;
25 following = true;
26 }
27 else
28 {
29 return;
30 }
31 }
32 else
33 {
34 if (input.Dragging)
35 {
36 Vector3 target = camOnPress - (new Vector3(input.DragVector.x, 0, input.DragVector.y) * factor);
37 this.transform.position = Vector3.Lerp(this.transform.position, target, Time.deltaTime*.5f);
38 }
39 else
40 {
41 camOnPress = Vector3.zero;
42 following = false;
43 }
44 }
45 }
46 }
2 using System.Collections;
3
4 public class ClickAndDrag : Photon.MonoBehaviour
5 {
6 private Vector3 camOnPress;
7 private bool following;
8 private float factor = -0.1f;
9
10 // Update is called once per frame
11 void Update ()
12 {
13 if (!photonView.isMine)
14 {
15 return;
16 }
17
18 InputToEvent input = Camera.main.GetComponent<InputToEvent>();
19 if (input == null) return;
20 if (!following)
21 {
22 if (input.Dragging)
23 {
24 camOnPress = this.transform.position;
25 following = true;
26 }
27 else
28 {
29 return;
30 }
31 }
32 else
33 {
34 if (input.Dragging)
35 {
36 Vector3 target = camOnPress - (new Vector3(input.DragVector.x, 0, input.DragVector.y) * factor);
37 this.transform.position = Vector3.Lerp(this.transform.position, target, Time.deltaTime*.5f);
38 }
39 else
40 {
41 camOnPress = Vector3.zero;
42 following = false;
43 }
44 }
45 }
46 }
Update is called once per frame